<?php
declare(strict_types=1);
/**
 * MineAdmin is committed to providing solutions for quickly building web applications
 * Please view the LICENSE file that was distributed with this source code,
 * For the full copyright and license information.
 * Thank you very much for using MineAdmin.
 *
 * @Author X.Mo<root@imoi.cn>
 * @Link   https://gitee.com/xmo/MineAdmin
 */

namespace App\Goods\Mapper;

use App\Goods\Model\GoodsService;
use Hyperf\Database\Model\Builder;
use Mine\Abstracts\AbstractMapper;

/**
 * 承诺记录Mapper类
 */
class GoodsServiceMapper extends AbstractMapper
{
    /**
     * @var GoodsService
     */
    public $model;

    public function assignModel()
    {
        $this->model = GoodsService::class;
    }

    /**
     * 搜索处理器
     * @param Builder $query
     * @param array $params
     * @return Builder
     */
    public function handleSearch(Builder $query, array $params): Builder
    {
        
        // 商品服务ID
        if (isset($params['id']) && filled($params['id'])) {
            $query->where('id', '=', $params['id']);
        }

        // 服务名称
        if (isset($params['name']) && filled($params['name'])) {
            $query->where('name', 'like', '%'.$params['name'].'%');
        }

        // 概述
        if (isset($params['summary']) && filled($params['summary'])) {
            $query->where('summary', 'like', '%'.$params['summary'].'%');
        }

        // 是否默认(新增商品时)
        if (isset($params['is_default']) && filled($params['is_default'])) {
            $query->where('is_default', '=', $params['is_default']);
        }

        // 状态(1显示 0隐藏)
        if (isset($params['status']) && filled($params['status'])) {
            $query->where('status', '=', $params['status']);
        }

        // 排序方式(数字越小越靠前)
        if (isset($params['sort']) && filled($params['sort'])) {
            $query->where('sort', '=', $params['sort']);
        }

        // 是否删除(1已删除)
        if (isset($params['is_delete']) && filled($params['is_delete'])) {
            $query->where('is_delete', '=', $params['is_delete']);
        }

        // 商城ID
        if (isset($params['store_id']) && filled($params['store_id'])) {
            $query->where('store_id', '=', $params['store_id']);
        }

        // 创建时间
        if (isset($params['create_time']) && filled($params['create_time'])) {
            $query->where('create_time', '=', $params['create_time']);
        }

        // 更新时间
        if (isset($params['update_time']) && filled($params['update_time'])) {
            $query->where('update_time', '=', $params['update_time']);
        }

        return $query;
    }
}